require "net/http";
require "uri"

def post(url, data)
  headers = {
    "User-Agent" => "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/2.0.0.9"
  };
  url = URI.parse(url)
  res = Net::HTTP.new(url.host).start do |http|
    http.request_post(url.path, data, headers);
  end
  File.open("page.htm", "w"){|file| file << res.body}
  res;
end


class Webly
  
  class LoginError < StandardError; end
  
  def self.login(username, password)
    options = {"UserName" => username, "PassWord" => password};
    url = "http://forum.ievolutionweb.com/index.php?act=Login&CODE=01&CookieDate=1";
    net = Net::HTTP.post_form(URI.parse(url), options);
    raise LoginError if net.body.include?("Os seguintes erros foram encontrados");
    p net.class.superclass
    net.body
  end

end

post "http://forum.rubyonbr.org/sessions",
  "login" => "bermonruf",
  "password" => "..pass-here..",
  "remember_me" => "1",
  "commit" => "Login"
  
  
  